<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/include/includeHeader.jsp"%>
<%@ include file="/common/include/dictNames.jsp"%>
<%@ page import="java.util.*,
                 com.kylin.common.util.*,
                 com.kylin.common.paginate.DisplayPage,
                 com.kylin.common.dict.orm.Dict,
                 com.kylin.common.dict.orm.CatDict" %>
<%
    String language = request.getParameter("language");
    if(language == null)
        language = sessionLocale.toString();
    List catproduct = MemObjFactory.getDict(dict_catProducts);
    List parentList = new ArrayList();;
	if (catproduct != null){
		for (int i = 0; i < catproduct.size(); i++){  
			Dict dict = (Dict) catproduct.get(i);
			if (dict.getParent() == null) 
				parentList.add(dict); 
		}
	}
%>                 
<table>
<form name="fo1" action="/admin/shop/listProductDict.jsp">
	<tr>
		<td height="22" align="right"> 所属语言 </td>
		<td align="left">
      	  <mytag:national value="<%=language%>" name="language" 
      	       notEmpty="true" dictName="<%=Constants.SYSLANGUAGE%>" 
      	            onchange="changeSelect(this.value)"  />
		</td>
	</tr>
	<tr>
		<td height="19" align="right">
			所属分类
		</td>
		<td align="left">
      <select name="parent">
		<option value="">-- 请选择 --</option>
	  </select>

<div style="position:absolute; visibility:hidden; ">
  <select name="allDatalist" >
<%
    if(parentList != null){
        for(int i=0;i<parentList.size();i++){
           Dict parent = (Dict)parentList.get(i);
            out.print("\n <option language='"+parent.getLanguage()+"' ");
            out.print("   value='"+parent.getId()+"' >");
            out.print(parent.getName() + "</option> \n");
        }
        
    }
%>
  </select>
  <script>
		function changeSelect(language){
			var dataList = document.fo1.allDatalist;
			var targetList = document.fo1.parent;
			targetList.length = 1;
		    for(var i=0;i<dataList.length;i++){
		       if(dataList.options[i].language==language){
		           targetList.length = targetList.length+1;
		           targetList.options[targetList.length-1].value = dataList.options[i].value;
		           targetList.options[targetList.length-1].text  = dataList.options[i].text;	 
		       }
		    }
		}
		changeSelect(document.fo1.language.value); //页面显示后直接初始化
   </script>  
</div>
		</td>
	</tr>
	<tr>
		<td height="29" align="right"> &nbsp; </td>
		<td> <input type="submit" value="查询" /> </td>
	</tr>
</form>
</table>
<%
    List subProductCatList = new ArrayList();
	if (catproduct != null){
		for (int i = 0; i < catproduct.size(); i++){  
			Dict dict = (Dict) catproduct.get(i);
			if(!dict.getLanguage().equals(language))
			    continue;
			if( request.getParameter("parent")==null 
			        || request.getParameter("parent").equals("")  ){
			    if ( dict.getParent() == null ) subProductCatList.add(dict);
			}else{
			     Long id = new Long(request.getParameter("parent"));
			     if(dict.getParent()!= null && dict.getParent().getId().equals(id) )
			         subProductCatList.add(dict);
			}
		}
	}
	
%>
                 
             
<mytag:MyActionMsg />
<form name="optForm"  action="/admin/shop/manageShop.do" method="post">
<input type="hidden" name="CMD" >
<table class='pageTable' cellspacing='0' cellpadding='0'> 
    <tr>
        <td class='pageTitle'> </td>
        <td class='pageTitle'>排序号</td>
        <td class='pageTitle'>所属类别</td>
        <td class='pageTitle'>名称</td>
        <td class='pageTitle'>语言种类</td>
        <td class='pageTitle'>描述</td>
        <td class='pageTitle'>操作</td>
    </tr>
    
<%
    for(int i=0;i<subProductCatList.size();i++){
        Dict dict = (Dict)subProductCatList.get(i);
%>
    <tr class='row<%=(i%2)%>'> 
       <td class='pageTd'>
       	  <%=(i+1)%>(<%=dict.getId() %>) <input type="checkbox" name="ids" value="<%=dict.getId()%>"> 
       </td> 
       <td class='pageTd'><%=dict.getOrdering()%>  </td> 
       <td class='pageTd'>[ <%=(dict.getParent()!=null)?dict.getParent().getName():"" %>  ]</td> 
       <td class='pageTd'><%=dict.getName()%>      </td> 
       <td class='pageTd'><% try{out.println(UTool.getLanguageName(dict.getLanguage(),Locale.getDefault()) ); }catch(Exception e){}%>  </td> 
       <td class='pageTd'><%=JspHelper.checkNull(dict.getDescription())%>&nbsp;</td> 
       <td class='pageTd'>  <a href="#">编辑</a> </td> 
	</tr>
<%
    }
%>

</table> 
<script>
    function changeParent(){
	    if(document.optForm.parent.value==""){
	        alert("请选择目标 一级分类")
	        return;
	    }
	    if(confirm("确定要移动所选的数据吗？") == false)
	        return;
        document.optForm.CMD.value="changeParent";
        document.optForm.submit();
    }
</script>
<table width="100%">
   <tr>
      <td>
          <input type="button" onclick="changeParent()" value="移到其他分类下">
  <select name="parent" >
     <option value=""></option>
<%
    if(parentList != null){
        for(int i=0;i<parentList.size();i++){
           Dict parent = (Dict)parentList.get(i);
            out.print("\n <option language='"+parent.getLanguage()+"' ");
            out.print("   value='"+parent.getId()+"' >");
            out.print(parent.getName() + "</option> \n");
        }
        
    }
%>
  </select>
         
      </td>
 <td> 删除 </td>
 </tr></table>
 <br>
 